package date_demo;

/**
 * @author ChenYongHao
 * @date 2023/5/4 10:11
 * @desc 描述：时间戳，可以获取秒、毫秒、纳秒
 */

import java.time.Instant;

public class Instant_Demo {
    public static void main(String[] args) {
        // 创建Instant对象
        Instant instant = Instant.now();

        // 获取秒数
        long currentSecond = instant.getEpochSecond();
        System.out.println(currentSecond);

        // 获取毫秒数
        long currentMilli = instant.toEpochMilli();
        System.out.println(currentMilli);

        // 获取纳秒数
        int currentNano = instant.getNano();
        System.out.println(currentNano);
    }
}
